<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <!-- 标签页图标 -->
    <link rel="shortcut icon" href="/images/icon/menu_title_1.jpg" type="image/x-icon" />
    <!--<link href="css/mui.min.css" rel="stylesheet" />-->
    <style type="text/css">
        .inputBackground {
            /*background-color: #181818;*/
            background-color:#2D2D3F;
            border: 2px solid #FFFFFF;
            border-radius: 25px;
            height: 40px;
           color: #FFFFFF;
            width: 100%;
            padding: 0px;
            font-size: 20px;
        }
        .bodyCss{
            background: #CC95C0;  /* fallback for old browsers */
            background: -webkit-linear-gradient(to right, #7AA1D2, #DBD4B4, #CC95C0);  /* Chrome 10-25, Safari 5.1-6 */
            background: linear-gradient(to right, #7AA1D2, #DBD4B4, #CC95C0); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */

        }
    </style>
</head>

<!--<body style="background-color: #181818;">-->
<body class="bodyCss" style="margin: 0px;padding: 0px;">
<!--
作者：txd.cool@gmail.com
时间：2018-04-25
描述：jquery
-->
<script src="/js/layui/layui.all.js" charset="utf-8"></script>
<script src="/js/jquery.js" charset="utf-8"></script>
<script src="/js/localStorage.js" charset="utf-8"></script>

<div  style="width: 100px;height:100px;color: #2D2D3F;font-size:30px;margin: 0 auto;margin-top: 15%;">LOGIN</div>
<div class="mui-content" style="width: 90%;padding: 0px;margin: 0px auto;margin-top: 5%;">
    <input id="userName" type="text" class="inputBackground" value=""  style="text-indent: 1em;" placeholder="loginName"/>
    <br />
    <br />
    <input id="passWord" type="password" class="inputBackground" value="" style="text-indent: 1em;" placeholder="password"/>
    <br />
    <br />
    <input id="login" readonly ="readonly " type="text" class="inputBackground" value="登录" style="text-align:center;border-color:blue;"/>
    <br/>
    <br/>
    <br/>
    <button class="layui-btn layui-btn-primary" id="register" type="button" style="">注册账号</button>
    <button class="layui-btn " id="publicLogin" type="button" style="background-color: #3FDD86;float: right">游客登录</button>
</div>
</body>
<script>
    //localStorage.userName='';


    //注册账号
    $("#register").click(function() {
        var index = layer.open({
            type: 2,
            title: ["注册线上买卖通账号"],
            //title:false,
            closeBtn:1,
            //area: ['402px', '250px'], //['402px', '250px'],
            area:['100%','100%'],
            content: ['/v1.0/register', 'no']//'http://layer.layui.com/test/settop.html'// './addAuthCode.html' //这里content是一个普通的String
        });
        //layer.full(index);
    });

    var publicLoginKey = '测试账号';
    var publicLoginPwd = '1';
    //游客登录
    $("#publicLogin").click(function() {
        localStorage.userName = publicLoginKey;
        $("#userName").val(publicLoginKey);
        $("#passWord").val(publicLoginPwd);
        loginUser(true);
        //clearRemember();
    })

    //login
    function loginUser(messageFlag) {
        var userName = $("#userName").val();
        var passWord = $("#passWord").val();
        if(isBlank(userName)) {
            layer.msg("请输入账号");
            $("#userName").focus();
            return;
        }
        if(isBlank(passWord)) {
            layer.msg("请输入密码");
            $("#passWord").focus();
            return;
        }
        $.ajax(serverURL + '/user/loginUser', {
            type: "post",
            async: false,
            dataType: 'json', //服务器返回json格式数据
            data: {
                userName: userName,
                passWord: passWord
            },
            success: function(data) {
                if(isBlank(data.data)) {
                    if(messageFlag)
                        layer.msg(data.meta);
                    return;
                }
                //验证成功,加入session
                $.ajax('/v1.0/addSession', {
                    type: "post",
                    async: false,
                    dataType: 'json', //服务器返回json格式数据
                    data: {
                        userName: data.data.userName
                    },
                    success: function() {
                    },
                    error: function(e) {
                        console.log(e)
                    }
                });

                localStorage.userName = data.data.userName;
                localStorage.passWord = passWord;
                setLocalObject("user",data.data);
                window.location.href = "/";

            },
            error: function(e) {
                console.log(e)
            }
        });
    }
    $("#login").click(function() {
        loginUser(true);
    })

/*    //记住账号密码
    if(isNotBlank(localStorage.userName) && localStorage.userName != publicLoginKey) {
        $("#userName").val(localStorage.userName)
        if(isNotBlank(localStorage.passWord))
            $("#passWord").val(localStorage.passWord)
    }

    //自动登录
    if(isNotBlank(localStorage.userName) && isNotBlank(localStorage.passWord)&localStorage.userName!=publicLoginKey) {
        console.log(localStorage.userName);
        console.log(localStorage.passWord);
        loginUser(false);
    }*/


</script>
</html>